import requests


def send_http(base_url, endpoint, data, headers=None):
    """
    发送HTTP POST请求的通用方法
    
    Args:
        base_url: 基础URL
        endpoint: API端点
        data: 请求数据
        headers: 请求头，默认为None
    Returns:
        dict: 响应的JSON数据
    """
    if headers is None:
        headers = {'accept': 'application/json', 'Content-Type': 'application/json'}
    
    # 根据Content-Type判断是否为form-data请求
    if headers.get('Content-Type') == 'application/x-www-form-urlencoded':
        response = requests.post(
            f"{base_url}{endpoint}",
            headers=headers,
            data=data  # 使用data参数发送form-data
        )
    else:
        response = requests.post(
            f"{base_url}{endpoint}",
            headers=headers,
            json=data  # 使用json参数发送json数据
        )
    return response.json()


def send_http_stream(base_url, endpoint, data, headers=None):
    """
    发送HTTP POST流式请求的通用方法
    
    Args:
        base_url: 基础URL
        endpoint: API端点
        data: 请求数据
        headers: 请求头，默认为None
    Returns:
        requests.Response: 流式响应对象
    """
    if headers is None:
        headers = {'accept': 'application/json', 'Content-Type': 'application/json'}
    
    response = requests.post(
        f"{base_url}{endpoint}",
        headers=headers,
        json=data,
        stream=True
    )
    return response

